package com;

import com.yuhang.demo.util.PostUtil;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @user yuhang
 * @desc
 * @since 2021/10/26
 */
public class ErpTest {

    public static String api = "http://apierp.go2b2b.com";

//    public static String api = "http://127.0.0.1:36162";


//    static String token = "rNPG67+3YKBiOYZJPCjwEzL3xW9W5SLBNhTIyWoAAn3Xlx/DhFZ7U/TgjWcwGgUZ";

    static String token ="HNLBVCURjmiECI+xlrsOw1uyuBZsHc/lyqOaQZZTyMuCVLDjt6mBHqnN9u9GPWH6";

    public static void main(String[] args) throws IOException {

//        String result = loginweb();
        String result = getSn();
//        String result = getSkuBySn();
//        String result =queryProductSkuBySn();
//        String result =saleList();
        System.out.println(result);
    }






    private static String getSkuBySn() throws IOException {
        String url = api + "/api/sale/getSkuBySn";
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("type", "1"));//264
        formparams.add(new BasicNameValuePair("supplierId", "27"));
        formparams.add(new BasicNameValuePair("sns", "04200017330000001"));
        formparams.add(new BasicNameValuePair("customerId", "92"));//登录类型：1 - 厂家端 2 - 工厂端
        formparams.add(new BasicNameValuePair("token", token));
        return PostUtil.httpPost(url, formparams);
    }


    /**
     * @return
     * @throws IOException
     */
    private static String loginweb() throws IOException {
        String url = api + "/loginweb";
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("username", "18523502645"));//264
        formparams.add(new BasicNameValuePair("password", "123456"));
        formparams.add(new BasicNameValuePair("platformType", "1"));//登录类型：1 - 厂家端 2 - 工厂端
        return PostUtil.httpPost(url, formparams);
    }

    private static String getSn() throws IOException {
        String url = api + "/api/product/getSnBatch";
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("token", token));
        formparams.add(new BasicNameValuePair("json", "[{\"skuId\": 23246, \"sizeList\":[{\"size\":\"34\", \"quantity\": 1}]}]"));//264
        return PostUtil.httpPost(url, formparams);
    }


    private static String queryProductSkuBySn() throws IOException {
        String url = api + "/api/product/queryProductSkuBySn";
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("supplierId", "27"));
        formparams.add(new BasicNameValuePair("token", token));
        formparams.add(new BasicNameValuePair("sns","04700002340000002"));//264
        return PostUtil.httpPost(url, formparams);
    }

    private static String saleList() throws IOException {
        String url = api + "/api/sale/saleList";
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("state", "1"));
        formparams.add(new BasicNameValuePair("token", token));
        formparams.add(new BasicNameValuePair("artNo", "'CY00' select * from sales_detail '"));
        return PostUtil.httpPost(url, formparams);
    }

}
